/**
 * Created by Fisnail on 2014/12/15.
 */

var findAllUsers = function(){
    $trUserIn = $("#userTableIn");
    $trUserOut = $("#userTableOut");
    $trUserIn.find("tr").not(":eq(0)").remove()
    $trUserOut.find("tr").not(":eq(0)").remove()
    $.ajax({
        url: serverAddress + "users/all", success: function (users) {
            $.each(users, function (i, user) {

                $tr = $("<tr>"
                + "<td>"+user.id+"</td>"
                + "<td>"+user.name+"</td>"
                + "<td>"+user.img+"</td>"
                + "<td>"+(user.ch=="1"?"已签到":"未签到")+"</td>"
                + "<td>"+user.zj+"</td>"
                + "</tr>");
                if(user.ch=='0'){
                    $trUserOut.append($tr);

                }else{
                    $trUserIn.append($tr);
                }

            });
        }
    });
}
$(function () {


    var socket = io.connect(serverPath);
    socket.emit("server.login",{id:"signIn"});
    findAllUsers();
    socket.on('client.signin',function(msg){
        if(msg.cmd=="ok"){
            findAllUsers();
        }
    })

    $('#btn').click(function(){
        var userName = $('#userVal').val();
        console.log(userName)
        $('#qrImg').attr("src","ewm/"+userName+".png");
    });

});
